1. Field of the Invention
The present invention is directed to endianness in data structures.
2. Description of the Related Art
When hardware components and software modules transmit data to each other, they often pack the data before transmission and unpack the data upon receipt of the data. When packing smaller data elements into larger ones, different combinations of hardware and/or software may do the packing in different fashions. For example, when packing bytes into a 32-bit word, one piece of hardware/software may put the first byte in the least significant position of the word, while another piece may put it in the most significant position. These two pieces of data-packing hardware are said to have different endiannesses.
Endianness is an attribute of a system that indicates whether data values are represented from left to right or right to left. Big endian means that the most significant byte of any multibyte data field is stored at the lowest memory address, which is the larger field address. Little endian means that the least significant byte of any multibyte data field is stored at the lowest memory address, which is also the address of the larger field. Processors and other data processing modules are typically designated as either big endian or little endian. For example, Intel's 80×86 processors and their clones are little endian devices, while Sun's SPARC, Motorola's 68K, and the PowerPC family processors are all big endian devices.
A problem occurs when hardware or software tries to interpret a data structure that was received from hardware or software having a different endianness. In this case, data elements in the received data structure are not where the receiving hardware or software expects them to be. As a result, the data structure is interpreted incorrectly.
Currently, endianness control bits are used in hardware to configure the hardware to interpret a structure in multiple endianness. To use these endianness control bits, a software driver requires an understanding of the entire system in which the hardware operates in order to determine how different pieces of hardware should interpret the structure. It then has to configure the hardware's endianness control bits. This requires each hardware piece to know the endianness of every other instance of data processing hardware and software that may pack or unpack data.
Another current approach is to use software drivers to convert data structures from one endianness to another when necessary. This process includes interpreting the data in one endianness and translating the data structure from one endianness to another (a process known as swizzling). This swizzling process may waste processing time and large numbers of valuable CPU cycles.